package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.pojo.CheckPrVO;
import com.gxa.zhonglong.pojo.PrGet;
import com.gxa.zhonglong.pojo.PurchaseReturn;
import com.gxa.zhonglong.service.CheckPrVOService;
import com.gxa.zhonglong.service.PrGetService;
import com.gxa.zhonglong.service.PurchaseReturnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Api("采购退货视图的接口")
@CrossOrigin
@RestController
@RequestMapping("/checkpr")
public class CheckPrVOController {
    @Autowired
    CheckPrVOService checkPrVOService;
    @Autowired
    PrGetService prGetService;
    @Autowired
    PurchaseReturnService purchaseReturnService;

    @PostMapping("/selectbycd")
    @ApiOperation("selectByCondition")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name="purchaseReturn",value = "采购退货对象",dataType = "PurchaseReturn",paramType ="body")
            }
    )
    public Map<String,Object> selectByCondition(@RequestBody PurchaseReturn purchaseReturn,@ApiIgnore HttpServletRequest request){
        Map parameterMap = request.getParameterMap();
        Set set = parameterMap.entrySet();
        set.forEach(System.out::println);
        List<CheckPrVO> list = checkPrVOService.selectByCondition(purchaseReturn);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(list);
        return  jsonResult.getDataMap();
    }

    @GetMapping("/selectAll")
    public Map<String,Object> selectAll(@RequestParam("page") Integer page,@RequestParam("size") Integer size){
        Map<String, List<CheckPrVO>> list = checkPrVOService.selectAll(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(list);
        return  jsonResult.getDataMap();
    }

    @ApiOperation(value = "删除采购订单视图")
    @GetMapping("/delet")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "单据编号",paramType = "String")
    })
    public Map delete(String num){
        prGetService.delete(num);
        purchaseReturnService.delete(num);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("删除成功");
        return  jsonResult.getDataMap();
    }

}
